package cn.tedu.fy.pethome.ex.handler;

import cn.tedu.fy.pethome.ex.ServiceException;
import cn.tedu.fy.pethome.web.JsonResult;
import cn.tedu.fy.pethome.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {





    @ExceptionHandler
    public JsonResult handlerServiceException(ServiceException e){
      log.debug("统一处理异常机制处理ServiceException");
      return JsonResult.fail(e);
    }

    @ExceptionHandler
    public JsonResult handlerThrowable(Throwable e){
        log.debug("统一处理异常机制发现未知异常");
        e.printStackTrace();
        return JsonResult.fail(ServiceCode.ERR_UNKNOWN,e.getMessage());
    }



}
